{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "86abe7bd",
   "metadata": {},
   "source": [
    "- 记录人：杨茜\n",
    "- 记录时间：2021-12-6\n",
    "- 记录内容：回顾上周函数定义、调用等内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7db75308",
   "metadata": {},
   "source": [
    "> 1.函数的返回值                      \n",
    "> 2.函数的参数类型                           \n",
    "> 3.模块与函数的关系                          \n",
    "> 4.定义一个模块，然后调用模块                              \n",
    ">> A.调用模块                                     \n",
    ">> B.调用模块中的函数 \n",
    "\n",
    "> 5.模块与函数实践                               "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c90ce946",
   "metadata": {},
   "source": [
    "### 1.函数的返回值\n",
    "\n",
    "> 1.函数一定有返回值，不论语言种类                                                          \n",
    "> 2.在其他编程语言中（如C语言、JAVA等），返回值一定要写，不写会报错！对于Python(更高级的语言)如果不写返回值，给定默认值None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1051f2aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_formatted_name(first_name,last_name):\n",
    "    full_name = first_name + '' + last_name\n",
    "#     print(full_name)\n",
    "    return full_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "464df3c1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LiHua\n"
     ]
    }
   ],
   "source": [
    "print(get_formatted_name(\"Li\",\"Hua\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d6afd1eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "def log_in(username,password):\n",
    "    if username == \"Lihua\" and password == 123456:\n",
    "        return 1\n",
    "    else:\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "69f80166",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_in(\"Lihua\",12345)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b2982cb",
   "metadata": {},
   "source": [
    "### 2.函数的参数\n",
    "> 1.函数输入的参数\n",
    ">> 函数可以输入复杂的参数\n",
    ">>> A.函数参数为列表                                \n",
    ">>> B.函数参数为字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0554600a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def list_test(names):\n",
    "    print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "343ee781",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Lihua', 'Xiaofeng', 'Xiaoyang']\n"
     ]
    }
   ],
   "source": [
    "list_test([\"Lihua\",\"Xiaofeng\",\"Xiaoyang\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "757cad48",
   "metadata": {},
   "outputs": [],
   "source": [
    "def dict_test(request_header):\n",
    "    print(person)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56ffeabe",
   "metadata": {},
   "outputs": [],
   "source": [
    "dict_test(httpbin_get['headers'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d2c1cd1",
   "metadata": {},
   "source": [
    "### 2.函数输出的返回值\n",
    "\n",
    "> 1.返回值可以是字符串、数值、列表、字典 等数据（单一值）                                \n",
    "> 2.返回值是唯一的不可以有俩个（这是其他语言如C语言，Java等）                                          \n",
    "> 3."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e6fd4245",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test1_return():\n",
    "    return \"你好\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "e891c646",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'你好'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test1_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "596d3107",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test2_return():\n",
    "    return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "fd5540da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test2_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "8647b46a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test3_return():\n",
    "    return [1,2,3,4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "6c36c510",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test3_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eff4e859",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test4_return():\n",
    "    return httpbin_get['headers']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f742a942",
   "metadata": {},
   "outputs": [],
   "source": [
    "test4_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "3870c9b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 测试多个值\n",
    "\n",
    "def test5_return():\n",
    "    return 1,2,\"Lihua\",[1,2,3],{\"name\":\"Alex\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "7c89a125",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 'Lihua', [1, 2, 3], {'name': 'Alex'})"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test5_return()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0c67ce2",
   "metadata": {},
   "source": [
    "> 2.函数可以输入不确定个数的参数：\n",
    "\n",
    ">> 1.*args                                          \n",
    ">>> 1.args 可以接收多个数据（单值）                                                  \n",
    ">>> 2.args 将多个数据存在于一个**元组**中，实际上还是变量    \n",
    "\n",
    ">> 2.* kwargs                                           "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "35c0e2f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "def food_ingred(food,*ingreds):\n",
    "    return food,ingreds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "3bc86b0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('pizza', ('mushroom', 'green peppers', 'cheese'))"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food_ingred(\"pizza\",\"mushroom\",\"green peppers\",\"cheese\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1248227",
   "metadata": {},
   "outputs": [],
   "source": [
    "def persom(stus_name,**stud_info):\n",
    "    return stud_name,stud_info"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
